package com.rpc.config;

import com.rpc.annotation.PropertiesPrefix;
import com.rpc.annotation.RpcPropertiesField;
import com.rpc.common.constants.RegistryRules;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * PrayRpcProperties
 * 配置类
 * @author 春江花朝秋月夜
 * @since 2024/1/18 11:37
 */
@PropertiesPrefix(value = "pray.rpc")
public class PrayRpcProperties {
    /**
     * 配置netty
     */
    @RpcPropertiesField
    private Integer port;
    @RpcPropertiesField
    private String registerAddr;
    @RpcPropertiesField
    private String registerType= RegistryRules.REDIS;
    @RpcPropertiesField
    private String registerPwd;
    @RpcPropertiesField
    private String  serialization;
    @RpcPropertiesField("service")
    private Map<String,Object> serviceAttachments=new HashMap<>();//额外配置项

    static PrayRpcProperties rpcProperties;
    //实例化
    public static PrayRpcProperties getInstance()
    {
        if (rpcProperties==null)
        {
            rpcProperties=new PrayRpcProperties();
        }
        return rpcProperties;
    }
    private PrayRpcProperties(){}//不对外提供构造方法

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getRegisterAddr() {
        return registerAddr;
    }

    public void setRegisterAddr(String registerAddr) {
        this.registerAddr = registerAddr;
    }

    public String getRegisterType() {
        return registerType;
    }

    //有特殊设置，所以单独拎出来
    public void setRegisterType(String registerType) {
        if (registerType==null||registerType.equals(""))
        {
            registerType=RegistryRules.REDIS;
        }
        this.registerType = registerType;
    }

    public String getRegisterPwd() {
        return registerPwd;
    }

    public void setRegisterPwd(String registerPwd) {
        this.registerPwd = registerPwd;
    }

    public String getSerialization() {
        return serialization;
    }

    public void setSerialization(String serialization) {
        this.serialization = serialization;
    }

    public Map<String, Object> getServiceAttachments() {
        return serviceAttachments;
    }

    public void setServiceAttachments(Map<String, Object> serviceAttachments) {
        this.serviceAttachments = serviceAttachments;
    }

    public static PrayRpcProperties getRpcProperties() {
        return rpcProperties;
    }

    public static void setRpcProperties(PrayRpcProperties rpcProperties) {
        PrayRpcProperties.rpcProperties = rpcProperties;
    }
}
